package com.example.ecas.service.impl;

import com.example.ecas.persistence.DisRcaseMapper;
import com.example.ecas.persistence.DisRtagMapper;
import com.example.ecas.persistence.DiseaseMapper;
import com.example.ecas.persistence.TagMapper;
import com.example.ecas.pojo.DisRcase;
import com.example.ecas.pojo.DisRtag;
import com.example.ecas.pojo.Disease;
import com.example.ecas.pojo.Tag;
import com.example.ecas.service.DiseaseService;
import com.example.ecas.service.WordCloudService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DiseaseServiceImpl implements DiseaseService {

    @Autowired
    DiseaseMapper diseaseMapper;

    @Autowired
    TagMapper tagMapper;

    @Autowired
    DisRtagMapper disRtagMapper;

    @Autowired
    WordCloudService wordCloudService;

    @Autowired
    DisRcaseMapper disRcaseMapper;

    // 获取对应病类的词云
    @Override
    public String getDisWordCloudB64(int id) {
        Disease disease = diseaseMapper.getDisease(id);
        if (disease == null) {
            return null;
        }
        List<DisRtag> disRtags = disRtagMapper.getDisRtagByDis(id);
        if (disRtags == null || disRtags.isEmpty()) {
            return null;
        }
        try {
            return wordCloudService.getWordCloudBase64(disRtags);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public List<Disease> getDiseasesByCase(int caseId) {
        List<Disease> result = new ArrayList<>();
        List<DisRcase> disRcases = disRcaseMapper.getDisRcaseByCase(caseId);
        for (DisRcase disRcase : disRcases) {
            result.add(diseaseMapper.getDisease(disRcase.getDisId()));
        }
        return result;
    }

}
